﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LinkCard.AdminCP.Common;
using LinkCard.Model;

namespace LinkCard.CustomerView
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            error.Visible = false;
        }

        protected void checkLogin(string sUsername, string sUserPw)
        {
            var db = new TopLinkEntities();
            var _customer = db.Customers.Where(t => t.Username == sUsername && t.Password == sUserPw).FirstOrDefault();
            
            if (_customer != null)
            {
                Session["USER"] = sUsername;
                Session["USERID"] = _customer.CustomerID;
                Session.Timeout = 19;
                Response.Redirect("transaction_report.aspx");
            }
            else
            {
                error.Visible = true;
            }


        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string sUsername = username.Value.ToUpper().Trim(); 
            sUsername = hash1way.SQLPatch(sUsername);
            string sUserPw = adminpassword.Value.ToUpper().Trim(); 
            sUserPw = hash1way.SQLPatch(sUserPw);
            checkLogin(sUsername, sUserPw);
        }
    }
}